package logic

import (
	"context"
	"time"

	"jinrigaoping/rpc/sys/internal/model"
	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysUserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysUserUpdateLogic {
	return &SysUserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysUserUpdateLogic) SysUserUpdate(in *sys.SysUserUpdateReq) (*sys.SysUserUpdateRes, error) {

	// 增加系统用户
	if err := l.svcCtx.SysUserModel.Update(l.ctx, &model.SysUser{
		Id:         in.Id,
		RoleId:     in.RoleId,
		UpdateTime: time.Now(),
		Phone:      in.Phone,
		Email:      in.Email,
		Brief:      in.Brief,
		Nickname:   in.Nickname,
	}); err != nil {
		logx.Errorf("SysUserUpdate params: %v error: %v", in, err)
		return nil, err
	}

	return &sys.SysUserUpdateRes{}, nil
}
